package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Emp;
import cn.gson.springboot.model.pjos.Warehouse;
import cn.gson.springboot.model.service.afterservice.WarehouseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/hou")
public class WarehouseController {

    @Autowired
    WarehouseService sc;

    @RequestMapping("/bank-page")
    @ResponseBody
    public Map<String,Object> bankPage(String states, String search, Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Warehouse> bank = sc.selectBankPage(states,search);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;     //总条数
    }

    @RequestMapping("/save-bank")
    @ResponseBody
    public void saveBank(@RequestBody Warehouse bank){
        sc.addBank(bank);
    }

    @RequestMapping("/update-bank")
    @ResponseBody
    public Warehouse updateBank(Integer bankId){
        return sc.checkBank(bankId);
    }

    @RequestMapping("/delete-bank")
    @ResponseBody
    public void deleteBank(Integer bankId){
        sc.delete(bankId);
    }
}
